package com.example.linyiquan.application.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;

import com.example.linyiquan.application.R;

/**
 * Created by linyiquan on 17-4-20.
 */

public class WelcomeActivity extends Activity {

    private boolean first=false;

    private static final int Time=1000;
    private static final int Login_Time=1001;
    private static final int Guide_Time=2000;

    private SharedPreferences sp;
    private SharedPreferences.Editor spe;

    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case Login_Time:
                    Go_Login();
                    break;
                case Guide_Time:
                    Go_Guide();
                    break;
            }
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);

        init();
    }

    private void init(){
        sp=getSharedPreferences("welcome",MODE_PRIVATE);
        first=sp.getBoolean("first",true);
        if(!first){
            handler.sendEmptyMessageDelayed(Login_Time,Time);
        }else {
            handler.sendEmptyMessageDelayed(Guide_Time,Time);
            spe=sp.edit();
            spe.putBoolean("first",false);
            spe.commit();
        }

    }

    private void Go_Login(){
        Intent login=new Intent(WelcomeActivity.this,LoginActivity.class);
        startActivity(login);
        finish();
    }

    private void Go_Guide(){
        Intent login=new Intent(WelcomeActivity.this,GuideActivity.class);
        startActivity(login);
        finish();
    }

}
